package Exercise;

public class DoublePower {

	public static double power(double base, int exponent) {
		if (exponent == 0)
			return 1;
		if (exponent == 1)
			return base;
		boolean odd = exponent % 2 == 0;
		boolean symbol = exponent > 0;
		int mid = Math.abs(exponent) >> 1;
		double result = power(base, mid) * power(base, mid);
		result = odd ? result : result * base;
		result = symbol ? result : (1 / result);
		return result;
	}

	public static void main(String[] args) {
		System.out.println(power(3.0, 3));
	}

}
